<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:output method="xml" encoding="windows-1250" indent="yes"/>    

 <xsl:template match="/CView">
   <ConceptView id_work="{@id_cview}" name="{@name}" id_wstep="{@id_cvinclude}" active="{@active}">
     <xsl:apply-templates select="CVInclude"/>
   </ConceptView>
 </xsl:template>
 
 <xsl:template match="CVInclude">

   <xsl:variable name="implicit">
     <xsl:choose>
       <xsl:when test="@implicit='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="usecoll">
     <xsl:choose>
       <xsl:when test="@usecoll='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="select">
     <xsl:choose>
       <xsl:when test="@select='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="create">
     <xsl:choose>
       <xsl:when test="@creat='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="update">
     <xsl:choose>
       <xsl:when test="@update='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="delete">
     <xsl:choose>
       <xsl:when test="@delete='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="detail">
     <xsl:choose>
       <xsl:when test="@detail='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="allowxml">
     <xsl:choose>
       <xsl:when test="@allowxml='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="virtual">
     <xsl:choose>
       <xsl:when test="@virtual='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="canexport">
     <xsl:choose>
       <xsl:when test="@canexport='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="concept">
     <xsl:choose>
       <xsl:when test="@path='../..'"></xsl:when>
       <xsl:otherwise><xsl:value-of select="Concept/@name"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <Include 
     allowxml="{$allowxml}" 
     canexport="{$canexport}"
     concept="{$concept}" 
     create="{$create}" 
     deforderby="{@deforderby}"
     delete="{$delete}" 
     detail="{$detail}" 
     hasflap="{@hasflap}" 
     id_wstep="{@id_cvinclude}" 
     implicit="{$implicit}" 
     isdistinct="{@isdistinct}" 
     nickname="{@nickname}"
     nickcoll="{@nickcoll}"
     path="{@path}"
     select="{$select}" 
     treelist="{@treelist}" 
     update="{$update}" 
     usecoll="{$usecoll}" 
     useleftouterjoin="{@useleftouterjoin}" 
     virtual="{$virtual}" 
     >
     <xsl:call-template name="CVICGroups"/>
     <xsl:apply-templates select="CVIRels/CVIRel"/>
     <xsl:apply-templates select="CVIProperties"/>
     </Include>
 </xsl:template>    


  <xsl:template name="CVICGroups">
    <xsl:if test="count(CVICGroups/CVICGroup)&gt;0">    
      <SubConditions>     
        <xsl:for-each select="CVICGroups/CVICGroup">
          <SubCondition type="{@type}">
            <xsl:for-each select="CVIConditions/CVICondition">
              <Condition operator="{@operator}" property="{@property}" type="{@type}" val="{@val}"/>
            </xsl:for-each>
          </SubCondition>
        </xsl:for-each>  
      </SubConditions>
    </xsl:if>
  </xsl:template>

 
 <xsl:template match="CVIRel">

   <IncIncRel id_wstepparent="{@id_cviparent}" id_wstepchild="{@id_cvichild}" seqnum="{@position}" required="*">
     <xsl:apply-templates select="CVInclude"/>
     <Relates>
        <xsl:call-template name="relates"/>
     </Relates>
   </IncIncRel>

 </xsl:template>
 
 <xsl:template name="relates">
   <xsl:variable name="linkname"><xsl:value-of select="CVInclude/@linkname"/></xsl:variable>
   <xsl:variable name="assoc" select="../../Concept/CAssociations/CAssociation[@linkname=$linkname][1]"/>
   <xsl:for-each select="$assoc/CABindings/CABinding">
     <xsl:sort select="@position" data-type="number" order="ascending"/>
     <Relate p1="{@p1}" p2="{@p2}" type="{../../@cardinality}"/> 
   </xsl:for-each>
 </xsl:template>


 <xsl:template match="CVIProperties">
   <Properties>
     <xsl:apply-templates select="CVIProperty[@useit='1']"/>
   </Properties>
 </xsl:template>


 <xsl:template match="CVIProperty">
   <xsl:variable name="mandat">
     <xsl:choose>
       <xsl:when test="@mandat='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="onlabel">
     <xsl:choose>
       <xsl:when test="@onlabel='0'">false</xsl:when>
       <xsl:otherwise>true</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <Property
     name="{@name}"
     onlist="{@onlist}"
     ondetail="{@ondetail}"
     oncreate="{@oncreate}"
     onedit="{@onedit}"
     onfilter="{@onfilter}"
     onlabel="{$onlabel}"
     mandat="{$mandat}"
     position="{@position}"
     default="{@default}"
     defaulttype="{@defaulttype}"
   >  
   </Property>
 </xsl:template>

</xsl:stylesheet>
       
 
